import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author zk
 * @date 2019-10-27 15:34
 */
public class AnnDemo {
    @Test
    public void annTest() throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Class<AnnDemo> clazz = AnnDemo.class;
        AnnDemo ad = clazz.newInstance();
        Method method = clazz.getMethod("show");
        Boolean flag = method.isAnnotationPresent(AnnTest.class);
        if(flag){
            AnnTest a = method.getAnnotation(AnnTest.class);
            Object invoke = method.invoke(ad);
            System.out.println(a.value() + invoke);
        }
    }

    /**
     * 注解只能在反射的时候才有用
     * @return
     */
    @AnnTest(value = "Say Hello,")
    public String show(){
        return "Tim";
    }
}
